import java.util.concurrent.*;

public class PoolTest {
    public static void main(String[] args) {
        ThreadOne t1 = new ThreadOne();
        ThreadOne t2 = new ThreadOne();
        ThreadOne t3 = new ThreadOne();
        ThreadOne t4 = new ThreadOne();
        ThreadTwo t5 = new ThreadTwo();
        //创建线程池
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        Future<Integer> submit = executorService.submit(t5);
        try {
            System.out.println(submit.get());
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
        //关闭线程池
        executorService.shutdown();
    }
}

class ThreadOne implements Runnable {
    @Override
    public void run() {
        System.out.println("线程开始运行");
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "我是线程名字");
        System.out.println("线程结束运行");
    }
}

//Callable带返回值，什么类型都可以加
class ThreadTwo implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        Thread.sleep(100);
        System.out.println(Thread.currentThread().getName());
        return 123;
    }
}